package xuegao.study.mall.order.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import xuegao.study.mall.common.model.oms.OmsOrderReturnReason;
import xuegao.study.mall.order.service.OmsOrderReturnReasonService;
import xuegao.study.mall.repo.dao.oms.OmsOrderReturnReasonDao;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class OmsOrderReturnReasonServiceImpl implements OmsOrderReturnReasonService {
    @Autowired
    private OmsOrderReturnReasonDao omsOrderReturnReasonDao;

    @Override
    public int create(OmsOrderReturnReason returnReason) {
        returnReason.setCreateTime(new Date());
        return omsOrderReturnReasonDao.insert(returnReason);
    }

    @Override
    public int update(Long id, OmsOrderReturnReason returnReason) {
        returnReason.setId(id);
        return omsOrderReturnReasonDao.updateById(returnReason);
    }

    @Override
    public int delete(List<Long> ids) {
        return omsOrderReturnReasonDao.deleteByIds(ids);
    }

    @Override
    public List<OmsOrderReturnReason> list(Integer pageSize, Integer pageNum) {
        PageHelper.startPage(pageNum, pageSize);
        return omsOrderReturnReasonDao.selectByMap(new HashMap<>());
    }

    @Override
    public int updateStatus(List<Long> ids, Integer status) {
        if (!status.equals(0) && !status.equals(1)) {
            return 0;
        }
        return omsOrderReturnReasonDao.updateStatusByIds(ids, status);
    }

    @Override
    public OmsOrderReturnReason getItem(Long id) {
        return omsOrderReturnReasonDao.selectById(id);
    }
}
